package hu.issue.entity;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "milestones")
public class Milestone {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	@Column(nullable = false)
	private String name;

	@ManyToOne
	@JoinColumn(name = "project_id")
	private Project project;

	@OneToMany(mappedBy = "milestone", cascade = CascadeType.PERSIST)
	private final List<Task> tasks = new LinkedList<Task>();

	protected Milestone() {

	}

	public Milestone(final String name) {
		this.name = name;
	}

	public void setProject(final Project project) {
		this.project = project;
	}

	public Integer getId() {
		return this.id;
	}

	public String getName() {
		return this.name;
	}

	public Project getProject() {
		return this.project;
	}

	public void addTask(final Task task) {
		task.setMilestone(this);
		this.tasks.add(task);
	}

	public List<Task> getTasks() {
		return this.tasks;
	}
}
